package com.zjitc.service.impl;

import com.zjitc.mapper.ShopMapper;
import com.zjitc.pojo.Page;
import com.zjitc.pojo.Product;
import com.zjitc.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShopServiceImpl implements ShopService {
    @Autowired
    private ShopMapper shopMapper;

    @Override
    public List<Product> queryProductAll(Page page) {
        return shopMapper.queryProductAll(page);
    }

    @Override
    public Product queryProductById(int id) {
        return shopMapper.queryProductById(id);
    }

    @Override
    public List<Product> queryProductByName(String name) {
        return shopMapper.queryProductByName(name);
    }

    @Override
    public int queryProductTotal() {
        return shopMapper.queryProductTotal();
    }

    @Override
    public Page getPage(){
        Page page = new Page();
        int dateTotal = queryProductTotal();
        int pageTotal = page.getPageTotal();
        pageTotal=(int)(dateTotal/page.getNumber())+1;
        page.setPageTotal(pageTotal);
        return page;
    }
}
